package com.gxuwz.Market.business.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gxuwz.Market.business.dao.ServiceClassDAO;
import com.gxuwz.Market.business.entity.ServiceClass;
import com.gxuwz.core.pagination.Result;

import net.sf.json.JSONObject;


@Service("serviceClassService")
public class ServiceClassImpl implements IServiceClassService {

	@Autowired
	private ServiceClassDAO serviceClassDAO;
	
	@Override
	
	public ServiceClass findById(int id) {
		// TODO Auto-generated method stub
		return serviceClassDAO.findById(id);
	}

	@Override
	public List<ServiceClass> findAll() {
		// TODO Auto-generated method stub
		return serviceClassDAO.findAll();
	}

	@Override
	public Result<ServiceClass> find(ServiceClass serviceClass, int page, int size) {
		// TODO Auto-generated method stub
		return serviceClassDAO.find(serviceClass, page, size);
	}

	@Override
	public List<ServiceClass> findByProperty(String property, String value) {
		// TODO Auto-generated method stub
		return serviceClassDAO.findByProperty(property, value);
	}

	@Override
	public void add(ServiceClass serviceClass) {
		serviceClassDAO.save(serviceClass);
	}

	@Override
	public void delete(int id) {
		// TODO Auto-generated method stub
		ServiceClass serviceClass = serviceClassDAO.findById(id);
		serviceClassDAO.remove(serviceClass);
	}

	@Override
	public void update(ServiceClass serviceClass) {
		// TODO Auto-generated method stub
		serviceClassDAO.update(serviceClass);
	}

	/**
	 * 通过专业异步查找班级列表
	 */
	@Override
	public List<ServiceClass> findAllClassByMajor(String JSON) {
		// TODO Auto-generated method stub
		List<ServiceClass> list = null;
		if(!"".equals(JSON) && null!=JSON){
			JSONObject obj = JSONObject.fromObject(JSON);
			try{
				if(null != obj){
					if(obj.has("majorId")&& !"".equals(obj.getString("majorId"))&& null != obj.getString("majorId")){
						list=serviceClassDAO.findAllClassByMajor(obj.getString("majorId"));
						
					}else{
						list = serviceClassDAO.findAll();
					}
					
				}
				
			}catch (Exception e) {
				e.printStackTrace();
			}
			
			
		}
		return list;
	}

}
